import { Component, OnInit } from '@angular/core';
import { Router } from "@angular/router";
import { User } from "./../model/user";
import { LoginService } from './../service/login.service';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {

  public user: User = new User();

  constructor(private router: Router, private loginService: LoginService) {  }

  ngOnInit() {

  }

  login() {
    this.loginService.userLogin(this.user.username, this.user.password).subscribe(result => {
      if (result.result === '00000000') {
        // this.user.userId = result.data.userId;
        // this.user.username = result.data.username;
        localStorage.clear();
        localStorage.setItem('userId', this.user.userId);
        localStorage.setItem('username', this.user.username);
        this.router.navigateByUrl('question');
      }else {
        alert(result.msg);
      }
    });
  }
}
